home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Technology Seed / Jan. '98 ATS.toast / NavServices1.0b3 / Navigation Services SDK / Examples / Sampler / Sampler ƒ / Common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  8.4 KB  |  337 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Common.h
  3.  
  4.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #ifndef __TYPES__
  9. #include <Types.h>
  10. #endif
  11.  
  12. #ifndef __DIALOGS__
  13. #include <Dialogs.h>
  14. #endif
  15.  
  16. #ifndef __LOWMEM__
  17. #include <LowMem.h>
  18. #endif
  19.  
  20. #ifndef __TEXTUTILS__
  21. #include <TextUtils.h>
  22. #endif
  23.  
  24. #ifndef __PRINTING__
  25. #include <Printing.h>
  26. #endif
  27.  
  28. #ifndef __APPLEEVENTS__
  29. #include <AppleEvents.h>
  30. #endif
  31.  
  32. #ifndef __QDOFFSCREEN__
  33. #include <QDOffscreen.h>
  34. #endif
  35.  
  36. #ifndef __NAVIGATION__
  37. #include "Navigation.h"
  38. #endif
  39.  
  40. #ifndef Common_Defs
  41. #define Common_Defs
  42.  
  43. #define kStr255Len            255        // this length is for NewPtr call, used before making a Toolbox call
  44. #define kNameLen            32        // file name length
  45.  
  46. enum checkboxstate { dechecked,checked };
  47.  
  48. #define kStrangeErr            -1
  49.  
  50. #define kActive                0
  51. #define kInactive            255
  52.  
  53. // ASCII key characters
  54. #define kCrChar                    13        // carriage return key 
  55. #define kDelChar                8        // delete key 
  56. #define kEnterChar                3        // enter char 
  57. #define kPeriodChar                46        // period char 
  58. #define kTabKey                    9        // tab char 
  59. #define kYKey                    121
  60. #define kNKey                    110
  61. #define kEscKey                    27
  62. #define kColon                    58
  63. #define kZero                    48
  64. #define kNine                    57
  65.  
  66. #define    dOK                        1
  67. #define dCancel                    2
  68.  
  69. #define kDelayTick                10        // ticks for button hiliting
  70. #define kWindowWidth            500        // width size for the text window
  71.  
  72. #define    kMaxDocumentCount        100        // maximum number of documents allowed
  73.  
  74. #define    InitialH                16
  75. #define    InitialV                42
  76.  
  77. #define    TopMargin                6
  78. #define    LeftMargin                6
  79. #define    RightMargin                6
  80. #define    BottomMargin            6
  81.  
  82. #define    ScrollResolution        12
  83.  
  84. #define kOpenRsrcID                300
  85. #define kOpenRsrcID2            301
  86.  
  87. // file constants
  88. #define    kFileCreator            'CPAP'
  89. #define    kFileType                'TEXT'
  90. #define kFileTypePICT            'PICT'
  91. #define kOpenRsrcType            'open'
  92.  
  93. // resource constants
  94. #define rIconSuite                128
  95.  
  96. #define iIconSuite                3
  97.  
  98. // alert resources constants:
  99. #define rSaveChangesID            128
  100. #define rRevertID                129
  101. #define rGenericAlertID            130
  102. #define rAboutID                131
  103.  
  104. // resource string constants
  105. #define    rAppStringsID            128
  106. enum {
  107.     sApplicationName = 1,
  108.     sTranslationLockedErr,
  109.     sTranslationErr,
  110.     sOpeningErr,
  111.     sReadErr,
  112.     sWriteToBusyFileErr,
  113.     sBusyOpen,
  114.     sChooseFile,
  115.     sChooseFolder,
  116.     sChooseVolume,
  117.     sCreateFolder,
  118.     sChooseObject,
  119.     sSaveCopyMessage,
  120.     slSavePromptIndex,
  121.     slClosingIndex,
  122.     slQuittingIndex
  123. };
  124.  
  125. #define    MenuStringsID            129
  126. enum {
  127.     slCantUndo = 1,
  128.     slUndoDrag,
  129.     slRedoDrag
  130. };
  131.  
  132. // menu resource constants
  133. #define    MenuBarID                128
  134.  
  135. #define    idAppleMenu                128
  136. #define    AboutItem                1
  137.  
  138. #define    idFileMenu                129
  139. #define    NewItem                    1
  140. #define    OpenItem                2
  141. #define    CloseItem                4
  142. #define    SaveItem                5
  143. #define SaveACopyItem            6
  144. #define    RevertItem                7
  145. //=
  146. #define DictionaryItem            9
  147. //=
  148. #define    PageSetupItem            11
  149. #define    PrintItem                12
  150. //=
  151. #define    QuitItem                14
  152.  
  153. #define    idEditMenu                130
  154. #define    iUndo                    1
  155. #define    iCut                    3
  156. #define    iCopy                    4
  157. #define    iPaste                    5
  158. #define    iClear                    6
  159. #define    iSelectAll                7
  160.  
  161. #define idUtilsMenu                131
  162. #define iSelectDir                1
  163. #define iSelectVol                2
  164. #define iSelectObject            3
  165. #define iCreateFolder            5
  166. #define iCustomOpen                7
  167.  
  168. #define kScrollBarWidth         16
  169. #define kScrollBarPos             kScrollBarWidth-1
  170.  
  171. // main document:
  172. typedef struct Document
  173. {
  174.     WindowPtr        theWindow;
  175.     TEHandle        theTE;
  176.     short            docTop;
  177.     RgnHandle        hiliteRgn;
  178.     
  179.     ControlHandle    vScroll;
  180.     ControlHandle    hScroll;
  181.     short            vScrollPos;
  182.     
  183.     short            fRefNum;
  184.     short            dirty;
  185.     
  186.     Handle            undoDragText;
  187.     short            undoSelStart;
  188.     short            undoSelEnd;
  189.     
  190.     short            lastSelStart;
  191.     short            lastSelEnd;
  192.  
  193.     ParamBlockRec    fioParamBlock;            // param block for file I/O operations
  194.     Handle            fPict;
  195.     Handle            fHeader;
  196.     long            fPictLength;
  197.  
  198. } Document;
  199.  
  200.  
  201. // offscreen drawing:
  202. typedef struct WindowOffscreen
  203. {
  204.     CGrafPtr        windowPort;
  205.     GDHandle        windowDevice;
  206.     GWorldPtr        offscreenWorld;
  207. } WindowOffscreen;
  208.  
  209. WindowOffscreen* DrawOffscreen(WindowPtr theWindow);
  210.  
  211.  
  212. #define mBarHeight    (short *)0x0BAA        // Low mem global for menu bar
  213. #define EventQueue  (QHdrPtr)0x14A         // Event queue header (10 bytes)
  214. #define Mouse        ((Point*)0x830)        // processed mouse
  215. #define KeyTime     (long*)0x186        // tickcount when KEYLAST was rec'd 
  216.  
  217. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  218. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  219.  
  220. #define RectWidth(aRect) ((aRect).right - (aRect).left)
  221. #define RectHeight(aRect) ((aRect).bottom - (aRect).top)
  222.  
  223. #define Max(X, Y) ( ((X)>(Y)) ? (X) : (Y) )
  224. #define Min(X, Y) (  ((X)>(Y)) ? (Y) : (X) )
  225.  
  226. #define Pin(VALUE, MIN, MAX) ( ((VALUE) < (MIN)) ? (MIN) : ( ((VALUE) > (MAX)) ? (MAX) : (VALUE) ) )
  227.  
  228. #define kOpenPrefKey            1
  229. #define kSavePrefKey            2
  230. #define kSelectFilePrefKey        3
  231. #define kSelectFolderPrefKey    4
  232. #define kSelectVolumePrefKey    5
  233. #define kNewFolderPrefKey        6
  234. #define kSelectObjectPrefKey    7
  235.         
  236. //**************************************************************
  237.  
  238. // utility routines for detecting keydowns
  239. Boolean ModifierDown(short modifier);
  240. Boolean OptionDown(void);
  241. Boolean ShiftDown(void);
  242. Boolean CommandDown(void);
  243. Boolean ControlDown(void);
  244.  
  245. static SInt16 rnd(SInt16 max);
  246. short RandTween(short low, short high);
  247.  
  248. // file utilities:
  249. OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName, short maxPathLength, short full);
  250. Boolean FSSpecsEq(FSSpec* a, FSSpec* b);
  251. pascal void myEventProc(NavEventCallbackMessage callBackSelctor, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD);
  252.  
  253. // dialog control utilities
  254. void hiliteTheButton(DialogPtr theDialog, short whichItem);
  255. void AdornButton(DialogPtr theDialog, short whichItem);
  256. unsigned char* GetItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  257. void PokeItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  258. void PokeCtlVal(DialogPtr theDialog, short theItem, short value);
  259. void PokeCtlHilite(DialogPtr theDialog, short theItem, short value);
  260.  
  261. // string utilities
  262. OSType Str2OSType(Str255 theStr);
  263. long MyStrLen(char* s);
  264. long myStringToLong(char* s);
  265. short myStringToShort(char* s);
  266. void myStrCpy(char* dst, char* src);
  267. void myStrCat(char* dst, char* src);
  268. unsigned char* ConcatPP(unsigned char* a,unsigned char* b);
  269. char* MyP2CCopy(unsigned char* psrc,char* ctarget);
  270. unsigned char* MyC2PStr(char* theStr);
  271. char* MyP2CStr(unsigned char* theStr);
  272.  
  273. void DrawIconSuite(short resID, Rect destRect);
  274. void DebugCStr(char* msg);
  275. void AdjustCursor(Point theLoc, RgnHandle theRgn);
  276.  
  277.  
  278. // *******************************************************************
  279.  
  280. // prototypes for 'document.c'
  281. Document* NewDocument(Boolean newAsPICT);
  282. Document* IsDocumentWindow(WindowPtr theWindow);
  283. void DoUndoDrag(void);
  284. pascal void DocumentClickLoop(void);
  285. void DoActivateDocument(Document* theDocument, short activate);
  286. void DoSelectAllDocument(Document* theDocument);
  287. void UpdateWindow(Document* theDocument);
  288. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint);
  289. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart);
  290. pascal void ScrollProc(ControlHandle theControl, short theCode);
  291. void DocumentHighlightProc(void);
  292. void SizeDocWindow(Document* theDocument);
  293.  
  294. // prototypes for 'files.c'
  295. short DoSaveDocument(Document* theDocument);
  296. void DoNewDocument(Boolean newDocAsPICT);
  297. OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT);
  298.  
  299. OSErr DoOpenDocument(void);
  300. OSErr DoOpenDocumentTheOldWay(void);
  301.  
  302. OSErr SaveACopyDocument(Document* theDocument);
  303. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  304.  
  305. void DoRevertDocument(Document* theDocument);
  306. void DoRevertDocumentTheOldWay(Document* theDocument);
  307.  
  308. // prototypes for 'Utilities.c'
  309. short TEIsFrontOfLine(short offset, TEHandle theTE);
  310. short TEGetLine(short offset, TEHandle theTE);
  311. short myTECut(TEHandle theTE);
  312. short myTEPaste(TEHandle theTE, short* spaceBefore, short* spaceAfter);
  313.  
  314. // prototypes for 'Offscreen.c'
  315. void DrawOnscreen(WindowOffscreen* theOffscreen);
  316.  
  317. // prototypes for 'document.c'
  318. void AdjustDocumentView(Document* theDocument);
  319. void AdjustScrollBar(Document* theDocument);
  320. void CloseDocument(Document* theDocument, Boolean quitting);
  321. void DisableUndoDrag(void);
  322. void AddText(Document* theDocument, Ptr text, long len);
  323.  
  324. // prototypes for 'drag.c'
  325. short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn);
  326.  
  327. // prototypes for 'menu.c'
  328. void AdjustMenus(void);
  329. void DoMenuCommand(long select);
  330.  
  331. // prototypes for 'event.c'
  332. void EventLoop(void);
  333. pascal OSErr MyHandleOAPP(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  334. pascal OSErr MyHandleODOC(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  335. pascal OSErr MyHandleQUIT(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  336.  
  337. #endif // Common_Defs